/**
 * Project: shuyin-sync
 * 
 * File Created at Apr 9, 2012
 * $Id$
 * 
 * Copyright 2008 6677bank.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * 6677bank Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with 6677bank.com.
 */
package com.bank6677.sync.csm.task;

import java.sql.SQLException;
import java.util.Date;

import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bank6677.sync.csm.service.ApplicationSyncService;

/**
 * 每日需要同步的做过改动的申请单。
 * <p>
 * 统计范围是前一天0点至24点，统计时间为0点1分
 * 
 * @author liyue
 * @version DailyAppsSyncTask.java Apr 9, 2012 1:13:01 PM
 */
@Service
public class DailyAppsSyncTask {

    @Autowired
    private ApplicationSyncService appSync;

    static Logger                  LOG                    = Logger.getLogger(DailyAppsSyncTask.class);

    static final String            DEFAULT_FORMAT_PATTERN = "yyyyMMdd";

    public void dailySynchronize() {
        String from = DateFormatUtils.format(DateUtils.addDays(new Date(), -1), DEFAULT_FORMAT_PATTERN);
        String to = DateFormatUtils.format(new Date(), DEFAULT_FORMAT_PATTERN);
        try {
            appSync.syncApplications(from, to);
        } catch (SQLException e) {
            LOG.error("每日同步贷款订单出错！", e);
        }
    }

}
